<?PHP
/**
 * $Rev: 8 $
 * $Id: renderer.php 8 2013-03-02 20:35:16Z vad.oparin@gmail.com $
 */
class renderer extends behavior {
	protected $layout;
	protected $layoutsDir;

	protected function setLayoutsDir($layoutsDir) {
		$this->layoutsDir = $layoutsDir;
	}

	protected function setLayout($layout) {
		$this->layout = $layout;
	}

	protected function getLayout() {
		return $this->layoutsDir . $this->layout . '.php';
	}

	public function render($view, $showing = array(), $return = false) {
		extract((is_array($showing)) ? $showing : array('showing' => $showing, ), EXTR_PREFIX_SAME, 'show');
		if ($return) {
			ob_start();
			ob_implicit_flush(false);
			include $view;
			return ob_get_flush();
		} else {
			include $view;
		}
	}

	public function renderPage($view, $showing = array()) {
		$title = $this->title;
		$showing = array(
			'title' => $this->title,
			'content' => $this->render($view, $showing, true),
		);
		$this->render($this->getLayout(), $showing);
	}

}
